$NG.AllReady(function (page, { useValuesChange,useDataIndexChange,useUpdateRows,useUpdateRow }) {
    const mstform = $NG.getCmpApi("p_form_zjxmndsrjh")
    const dgrid1 = $NG.getCmpApi("p_form_zjxmndsrjh_d")
    // 监听项目
    getPtInfoByPhid()
    cntMFilter()
    useValuesChange(({args})=>{
        console.log(`项目监听`,args[0]);
        getPtInfoByPhid()
        cntMFilter()
    },"p_form_zjxmndsrjh.phid_pc")
    //合同监听
    useValuesChange(({args})=>{
        console.log(`合同监听`,args[0]);
        getCntMInfoByPhid()
    },"p_form_zjxmndsrjh.u_htbh")
    //监听表体行为
    useUpdateRows(({args})=>{
      console.log(`表体监听`,args[0]);
      //汇总金额
      const table_month_key = ["u_yy","u_ey","u_sy","u_siyue","u_wy","u_ly","u_qy","u_by","u_jiuyue","u_shiyue","u_syy","u_sey"]
      args[0].forEach(item=>{
        item.u_bnhj= table_month_key.reduce((value,key)=>{
          value += (Number(item[key]) || 0)
          return value
        },0)
      })
      dgrid1.refreshView()
    },"p_form_zjxmndsrjh_d")




    /**
     * 
     * 功能扩展区
     * 
    */
    //获取项目信息
    function getPtInfoByPhid() {
        if (mstform.getItem("phid_pc").getValue()) {
          $NG.execServer("getPtInfoByPhid", { phid: mstform.getItem("phid_pc").getValue() }, function (res) {
            if(res.count == 0) return
            const datas = JSON.parse(res.data)[0].extendObjects;
            console.log(datas);
            $NG.updateState((updater) => {
              updater.data.p_form_zjxmndsrjh.setProps({
                //事业部
                u_syb: { value: datas.division_phid, label: datas.division_name },
                //区域中心
                u_qyzx: { value: datas.regional_center_phid, label: datas.regional_center_name },
                //产品线
                u_cpx: { value: datas.midwife_phid, label: datas.midwife_name },
              });
            });
          });
        }
    }
    //获取合同信息
    function getCntMInfoByPhid() {
        $NG.execServer("getCntMInfoByPhid", { phid: mstform.getItem("u_htbh").getValue() }, function (res) {
        if(res.count == 0) return 
          const datas = JSON.parse(res.data)[0].extendObjects;
          console.log(datas);
          $NG.updateState((updater) => {
            updater.data.p_form_zjxmndsrjh.setProps({
                u_ht_name: datas.pcm_name, //合同名称
            });
          });
        });
    }

    /**
     * 过滤区
     * */ 
    //合同根据项目ID过滤
    cntMFilter()
function cntMFilter() {
  $NG.updateUI((updater, state) => {
      console.log('过滤参数检查', updater);
      updater.form.p_form_zjxmndsrjh.u_htbh.setProps({
          onBeforeOpen: async () => {
              var phid_pc = $NG.getCmpApi('p_form_zjxmndsrjh').getItem('phid_pc').getValue();
              if (!phid_pc) {
                  $NG.alert("请先选择项目");
                  return false;
              } else {
                  return true;
              }
          },
          ...(!!$NG.getCmpApi('p_form_zjxmndsrjh').getItem('phid_pc').getValue() && {
              clientSqlFilter: {
                  bill_type: 1,//合同类型
                  phid_pc: $NG.getCmpApi('p_form_zjxmndsrjh').getItem('phid_pc').getValue()
              }
          }),
      });
  });
}
    
});

